$(function(){
    setTimeout(function(){
        $('.loadingbox').fadeOut();
    },200);
    var fisturl = window.location.href;
    $('.loading').css('margin-top', $(window).height()*0.382+'px');
    $.loadPage = function(url){
        $('#main-page').load(url+' #main-page > *', function(responseTxt, statusTxt, xhr){
            if (statusTxt == "success"){
                $('.loadingbox').fadeOut();
                $result = $(responseTxt);
                if(url!=window.location.href && $result.find("#nostate").length==0){
                    var oState = {url: url };
                    window.history.pushState(oState,null,url);
                }
                $(window).unbind('scroll');
                let pageTitle = responseTxt.match('\<title[^\>]*\>\s*(?<Title>.*?)\s*\</title\>')[1];
                $('title').text(pageTitle);
                window.shareData.title = pageTitle;
                window.shareData.link = url;
                window.shareData.desc = window.syssetShare.desc;
                $result.find("script").appendTo('#main-page');
                // seth();
            }else{
                window.location.href = url;
            }
        });
    }
    $('#main-page').on('click', 'a.ajax', function(e){
        e.stopPropagation(); 
        $('.loadingbox').fadeIn(50);
        var url = $(this).attr('href');
        $.loadPage(url);
        return false;
    });
    window.addEventListener("popstate", function() {
        $('.loadingbox').fadeIn(50);
        var oState = history.state;
        if(oState != null){
            $.loadPage(oState.url);
        }else{
            $.loadPage(fisturl);
        }
     });
    //  function seth(){
    //      var navh = $('#nav')?$('#nav').height():0;
    //      var coph = $('.copyright')?$('.copyright').height():0;
    //     $('#copyrightbox').css({'height':coph+navh+'px'});
    //     $('.copyright').css({'margin-top': '-'+(coph+navh)+'px'});
    //  }
    //  seth();
     $('.shade').height($(document).height());
});
function getQueryVariable(variable){
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
    }
    return(false);
}